package leetcode.秋招.米哈游;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2021/8/15 20:24
 * @description：
 */
public class Main1 {

    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.computeN(0));
    }

    public class Solution {
        /**
         * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
         *
         *
         * @param maxValue int整型 运算终点值
         * @return int整型
         */
        public int computeN (int maxValue) {
            // write code here
            int max = 0;
            for (int i = 0; i < maxValue; i++) {
                max = Math.max(max, f(i));
            }
            return max;
        }
        private int f(int n) {
            int digit = 1;
            int res = 0;
            int high = n / 10;
            int cur = n % 10;
            int low = 0;
            while (high != 0 || cur != 0) {
                if (cur == 0) res += high * digit;
                else if (cur == 1) res += high * digit + low + 1;
                else res += (high + 1) * digit;
                low += cur * digit;
                cur = high % 10;
                high /= 10;
                digit *= 10;
            }
            return res;
        }
    }
}
